package main

import (
	"fmt"
	"os"
	"os/exec"
)

func main() {

	os.Setenv("name", "lqz")
	//cmd := exec.Command("echo", os.ExpandEnv("$name"))
	cmd := exec.Command("echo", os.ExpandEnv("$name"))
	out, err := cmd.CombinedOutput()
	if err != nil {
		fmt.Println("执行出错:", err)
	}
	fmt.Printf("%s", out)

}

//ExpandEnv根据当前环境变量的值来替换字符串中的${var}或者$var。如果引用变量没有定义，则用空字符串替换
//s := "hello $GOROOT"
//fmt.Println(os.ExpandEnv(s))
